package com.joinlabs.action;

import java.util.List;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.joinlabs.entity.Log;
import com.joinlabs.entity.Topic;
import com.joinlabs.entity.User;
import com.joinlabs.entity.Weibo;
import com.joinlabs.service.ILogService;
import com.joinlabs.service.ITopicService;
import com.joinlabs.service.IUserService;
import com.joinlabs.service.IWeiboService;

@Controller
@RequestMapping("/search")
@SessionAttributes(names = {"weibolist","userlist","loglist","topiclist","topicdesc"})
public class SearchPageAction {

	@Resource
	private IWeiboService weiboService;
	
	@Resource
	private IUserService userService;
	
	@Resource
	private ILogService logService;
	
	@Resource
	private ITopicService topicService;
	
	
	//搜索微博界面
	@RequestMapping("/index")
	public ModelAndView index(ModelMap map) {
		List<Weibo> weiboList = weiboService.selectAllWeibo();
		List<Topic> topicDesc = topicService.selectDescTopic();
		map.addAttribute("weibolist",weiboList);
		map.addAttribute("topicdesc", topicDesc);
		return new ModelAndView("/search/allSearch");
	}
	
	//搜索找人界面
	@RequestMapping("/find")
	public ModelAndView find(ModelMap map) {
		List<User> userList = userService.selectAllUser();
		map.addAttribute("userlist", userList);
		return new ModelAndView("/search/findPeopleSearch");
	}
	
	//搜索文章界面
	@RequestMapping("/article")
	public ModelAndView article(ModelMap map) {
		List<Log> logList = logService.selectAllLog();
		map.addAttribute("loglist", logList);
		return new ModelAndView("/search/articleSearch");
	}
	
	//搜索话题界面
	@RequestMapping("/topic")
	public ModelAndView topic(ModelMap map) {
		List<Topic> topicList = topicService.selectAllTopic();
		map.addAttribute("topiclist", topicList);
		return new ModelAndView("/search/topicSearch");
	}
	
}